package io.renren.api.controller;

import io.renren.api.entity.BtCustomerBaseEntity;
import io.renren.api.entity.BtNavBarEntity;
import io.renren.api.service.BtCategroyManageService;
import io.renren.api.service.BtCustomerBaseService;
import io.renren.api.service.BtCustomerProBaseinfoService;
import io.renren.api.service.BtNavBarService;
import io.renren.api.vo.LunBoVo;
import io.renren.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller

public class FirstPageController {
    @Autowired
    private BtNavBarService btNavBarService;
    @Autowired
    private BtCategroyManageService btCategroyManageService;
    @Autowired
    private BtCustomerBaseService btCustomerBaseService;
    @Autowired
    private BtCustomerProBaseinfoService btCustomerProBaseinfoService;
    @RequestMapping("/")
    public String firstPage(Map<String,Object> backdata) {
        // modelAndView.setViewName("freemarker");
        List<BtNavBarEntity>  barlist = btNavBarService.getAllNavBar();
        backdata.put("barlist",barlist);
        //首页国内主题营分类
        List<Map<String,Object>> gnztfl = btCategroyManageService.getFirstfenleicatag();
        backdata.put("navlist",gnztfl);
        //首页轮播图
        List<LunBoVo> banner = btNavBarService.getFirstLunBo(1L);
        backdata.put("banner",banner);
        //获取首页分类(夏令营机构)
        Map<String, Object> params = new HashMap<>();
        params.put("page","1");
        params.put("limit","3");
        params.put("order","asc");
        PageUtils mechanism =btCustomerBaseService.queryPage(params);
        for(BtCustomerBaseEntity tb :(List<BtCustomerBaseEntity>)mechanism.getList()){
            tb.setLink("/api/dianpu/"+tb.getId());
        }
        backdata.put("mechanism",mechanism);
        //获取首页限时抢购列表
        List<Map<String,Object>> hotmap = btCustomerProBaseinfoService.getSalesPromotion();
        backdata.put("hotmap",hotmap);
        //首页国际游学
        Map<String,Object> guojiyx= btCustomerProBaseinfoService.getInternational();
        backdata.put("guojiyx",guojiyx);
        //首页国内营
        Map<String,Object> guoneiying= btCustomerProBaseinfoService.getDomestic();
        backdata.put("guoneiying",guoneiying);
        //首页周末营
        Map<String,Object> zhoumoying= btCustomerProBaseinfoService.getHoliday();
        backdata.put("zhoumoying",zhoumoying);
        return "index";
    }

    @RequestMapping("/login")
    public String login(Map<String,Object> backdata) {
        // modelAndView.setViewName("freemarker");
        //List<BtNavBarEntity>  barlist = btNavBarService.getAllNavBar();
        //backdata.put("barlist",barlist);
        return "login";
    }

    @RequestMapping("/register")
    public String register(Map<String,Object> backdata) {
        // modelAndView.setViewName("freemarker");
        //List<BtNavBarEntity>  barlist = btNavBarService.getAllNavBar();
        //backdata.put("barlist",barlist);
        return "register";
    }

    @RequestMapping("/shop")
    public String shop(Map<String,Object> backdata) {
        // modelAndView.setViewName("freemarker");
        //List<BtNavBarEntity>  barlist = btNavBarService.getAllNavBar();
        //backdata.put("barlist",barlist);
        return "shop/index";
    }

    @RequestMapping("/item")
    public String item(Map<String,Object> backdata) {
        // modelAndView.setViewName("freemarker");
        //List<BtNavBarEntity>  barlist = btNavBarService.getAllNavBar();
        //backdata.put("barlist",barlist);
        return "shop/item";
    }

    @RequestMapping("/sdynamic")
    public String sdynamic(Map<String,Object> backdata) {
        // modelAndView.setViewName("freemarker");
        //List<BtNavBarEntity>  barlist = btNavBarService.getAllNavBar();
        //backdata.put("barlist",barlist);
        return "shop/sdynamic";
    }

    @RequestMapping("/sdyitem")
    public String sdyitem(Map<String,Object> backdata) {
        // modelAndView.setViewName("freemarker");
        //List<BtNavBarEntity>  barlist = btNavBarService.getAllNavBar();
        //backdata.put("barlist",barlist);
        return "shop/sdyitem";
    }



}
